package com.huika.renrench.control.my.activity;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.Window;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.huika.lib.utils.MoneyShowTool;
import com.huika.renrench.R;
import com.huika.renrench.support.bean.BorrowRecordBean;
import com.huika.renrench.utils.DateTimeTool;
import com.huika.renrench.utils.PhoneUtil;
import com.huika.renrench.view.TitleBarHelper;

/**
 * @author yangyuan
 * @date：2015年6月3日
 * @describe:借款管理	
 */
public class MoneyDetailsActivity extends Activity implements OnClickListener{

	private int type = 0;
	BorrowRecordBean bean;
	
	private TextView borrow_money_11;
	private TextView borrow_money_12;
	private TextView borrow_money_21;
	private TextView borrow_money_22;
	private TextView borrow_money_31;
	private TextView borrow_money_32;
	private TextView borrow_money_41;
	private TextView borrow_money_42;
	private TextView borrow_money_51;
	private TextView borrow_money_52;
	private TextView borrow_money_61;
	private TextView borrow_money_62;
	private LinearLayout borrow_money_71;
	
	private LinearLayout lin_zhanwei;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		requestWindowFeature(Window.FEATURE_NO_TITLE);
		setContentView(R.layout.money_details_activity);
		
		type = getIntent().getExtras().getInt("type");
		bean = (BorrowRecordBean) getIntent().getExtras().getSerializable("BorrowRecordBean");
		
		borrow_money_11 = (TextView) findViewById(R.id.borrow_money_11);
		borrow_money_12 = (TextView) findViewById(R.id.borrow_money_12);
		borrow_money_21 = (TextView) findViewById(R.id.borrow_money_21);
		borrow_money_22 = (TextView) findViewById(R.id.borrow_money_22);
		borrow_money_31 = (TextView) findViewById(R.id.borrow_money_31);
		borrow_money_32 = (TextView) findViewById(R.id.borrow_money_32);
		borrow_money_41 = (TextView) findViewById(R.id.borrow_money_41);
		borrow_money_42 = (TextView) findViewById(R.id.borrow_money_42);
		borrow_money_51 = (TextView) findViewById(R.id.borrow_money_51);
		borrow_money_52 = (TextView) findViewById(R.id.borrow_money_52);
		borrow_money_61 = (TextView) findViewById(R.id.borrow_money_61);
		borrow_money_62 = (TextView) findViewById(R.id.borrow_money_62);
		borrow_money_71 = (LinearLayout) findViewById(R.id.borrow_money_71);
		lin_zhanwei = (LinearLayout) findViewById(R.id.lin_zhanwei);
		
		borrow_money_71.setOnClickListener(this);
		setView();
	}
	
	private void setView(){
		
		borrow_money_12.setText(MoneyShowTool.twolastDFStr(bean.getTargetAmount()));
		borrow_money_22.setText(bean.getLoanTime()+"个月");
		
		if (type==0) {
			new TitleBarHelper(this, R.string.left_back, -1, R.string.details0);
			borrow_money_31.setText("借款年化率    ");
			borrow_money_41.setText("借款状态    ");
			borrow_money_51.setText("借款时间    ");
			
			borrow_money_71.setVisibility(View.VISIBLE);
			lin_zhanwei.setVisibility(View.GONE);
			
			borrow_money_32.setText(bean.getYearRate()+"%");
			borrow_money_52.setText(DateTimeTool.ymdhmsDate(bean.getCreateTime()));
			
			SetViewState(borrow_money_42, bean.getLoanState());
		}else {
			new TitleBarHelper(this, R.string.left_back, -1, R.string.details1);
			borrow_money_31.setText("申请时间    ");
			borrow_money_41.setText("借款用途    ");
			borrow_money_51.setText("借款状态    ");
			
			borrow_money_32.setText(DateTimeTool.ymdhmsDate(bean.getCreateTime()));
			borrow_money_42.setText(bean.getIntroduction());
			borrow_money_62.setText(bean.getRemark());
			
			borrow_money_71.setVisibility(View.GONE);
			lin_zhanwei.setVisibility(View.VISIBLE);
			
			SetViewState(borrow_money_52, bean.getLoanState());
		}
	}

	@Override
	public void onClick(View v) {
		PhoneUtil.TelCALL(this, "400-613-6358");
	}
	
	private void SetViewState(TextView text_state,int LoanState){
		if (type==0) {
			if (LoanState==0) {
				text_state.setText("借款中");
				text_state.setTextColor(getResources().getColor(R.color.color_58bdee));
			}else if (LoanState==1)  {
				text_state.setText("已还款");
				text_state.setTextColor(getResources().getColor(R.color.color_5eb62f));
			}else {
				text_state.setText("");
			}
		}else {
			if (LoanState==0) {
				text_state.setText("审核中");
				text_state.setTextColor(getResources().getColor(R.color.color_fd6138));
			}else if (LoanState==1)  {
				text_state.setText("已通过");
				text_state.setTextColor(getResources().getColor(R.color.color_5eb62f));
			}else if (LoanState==2)  {
				text_state.setText("已拒绝");
				text_state.setTextColor(getResources().getColor(R.color.color_969696));
			}else {
				text_state.setText("");
			}
		}
	}
	
}
